﻿using System;
using System.IO.IsolatedStorage;
using System.Windows;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using SkiTracker.ViewModel;
using GestureEventArgs = System.Windows.Input.GestureEventArgs;

namespace SkiTracker.View
{
    public partial class MainPage : PhoneApplicationPage
    {
        public MainPage()
        {
            InitializeComponent();

            Click(1);

            DataContext = new MainViewModel();
        }


        #region Demo Stuff
        
        private void Id_OnTap(object sender, GestureEventArgs e)
        {
            IsolatedStorageSettings.ApplicationSettings.Remove("Id");
        }

        private void _1_Click(object sender, EventArgs e)
        {
            Click(1);
        }

        private void _2_Click(object sender, EventArgs e)
        {
            Click(2);
        }

        private void _3_Click(object sender, EventArgs e)
        {
            Click(3);
        }

        private void _4_Click(object sender, EventArgs e)
        {
            Click(4);
        }

        private void Click(int step)
        {
            var sender = (ApplicationBarIconButton) ApplicationBar.Buttons[step - 1];
            
            var controls = new UIElement[] {Login, Track, Locate, Messaging};
           
            var iconPath = sender.IconUri.OriginalString;
            var isChecked = iconPath.EndsWith("_.png");

            if (isChecked) step--;
            
            for (int i = 0; i < 4; i++)
            {
                controls[i].Visibility = (i < step) ? Visibility.Visible : Visibility.Collapsed;
                var button = (ApplicationBarIconButton) ApplicationBar.Buttons[i];
                button.IsEnabled = true; // (i <= step);
                var path = string.Format("/Assets/AppBar/{0}{1}.png", i + 1, i < step ? "_" : string.Empty);
                button.IconUri = new Uri(path, UriKind.Relative); 
            }
        }
        
        #endregion

    }

}